package thread;

public class homeword {
    private static Object chopstick = new Object();
    private static Object spoon = new Object();

    public static void main(String[] args) {
        Thread np = new Thread(){
            public void run(){
                try {
                    System.out.println("北方人开始吃饭...");
                    System.out.println("北方人去拿筷子...");
                    synchronized (chopstick){
                        System.out.println("北方人拿起了筷子开始吃饭...");
                        Thread.sleep(5000);
                        System.out.println("北方人吃完了饭，去拿勺...");
                        synchronized (spoon){
                            System.out.println("北方人拿起了勺开始喝汤...");
                            Thread.sleep(5000);
                            System.out.println("北方人喝完了汤");
                        }
                        System.out.println("北方人放下了勺");
                    }
                    System.out.println("北方人放下了勺");
                    System.out.println("北方人吃饭完毕！");
                } catch (Exception e) {
                }
            }
        };

        Thread sp = new Thread(){
            public void run(){
                try {
                    System.out.println("南方人开始吃饭...");
                    System.out.println("南方人开始吃饭...");
                    synchronized (spoon){
                        System.out.println("南方人拿起了勺开始喝汤...");


                    }
                } catch (Exception e) {
                }


            }



        };


    }
}
